package com.wn55.hrms.service;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.wn55.hrms.entity.Position;
import com.wn55.hrms.entity.PositionLevel;
import com.wn55.hrms.mapper.PositionMapper;
import com.wn55.hrms.service.vo.PositionVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * @author 赵明杰
 * @date 2022/05/05/18:40
 */
@Service
public class PositionService {
    @Autowired
    PositionMapper positionMapper;

    public List<Position> initPosition() {
        return positionMapper.selectAll();
    }

    /**
     * 查询
     * @param currentPage
     * @param pageSize
     * @param name
     * @return
     */
    public PageInfo<PositionVo> selectPositionByCondition(Integer currentPage, Integer pageSize, String name) {
        PageHelper.startPage(currentPage,pageSize);
        List<PositionVo> list = positionMapper.selectPositionByCondition(name);
        return new PageInfo<>(list);
    }

    /**
     * 添加职位
     * @param position
     */
    public void addPosition(Position position) {
        positionMapper.insert(position);

    }

    /**
     * 修改职位
     * @param position
     */
    @Transactional(rollbackFor = Exception.class)
    public void editPosition(Position position) {
        positionMapper.updateByPrimaryKey(position);
    }

    /**
     * 根据ID删除职位
     * @param id
     */
    @Transactional(rollbackFor = Exception.class)
    public void deletePositionById(int id) {
        positionMapper.deleteByPrimaryKey(id);
    }

    public List<Position> initPositionByDept(Integer deptId) {
        return positionMapper.selectByDeptId(deptId);
    }
}
